import java.util.Scanner;
import test.*;
import java.util.InputMismatchException;
public class Main {
    public static void main(String[] args) {
        MyArray array = new MyArray();
        array.getArray();
        Scanner scan = new Scanner(System.in);
        int num = 0;
        boolean flag = true;
        while(flag) {
            System.out.println("请输入你要取出的数的下标");
            int n = scan.nextInt();
            //System.out.println("n = " + n);
            try {
                num = array.getNum(n);
            }catch(OutOfBoundsException e) {
                System.out.println("访问越界了");
                System.out.println("请重新输入");
                continue;
            }
            System.out.println("num = " + num);
            flag = false;
        }
        scan.close();
    }
}



/*
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        String userName = "gaobo";
        String passWord = "123456";
        Scanner scanner = new Scanner(System.in);
        try {
            System.out.println("请输入用户名");
            String name = scanner.nextLine();
            System.out.println("请输入密码");
            String word = scanner.nextLine();
            if(!word.equals(passWord)) {
                throw new PassWordErrorException();
            }
            if(!name.equals(userName)) {
                throw new UserNameErrorException();
            }
        }catch(PassWordErrorException e) {
            e.printStackTrace();
            System.out.println("密码错误");
        }catch(UserNameErrorException e) {
            e.printStackTrace();
            System.out.println("用户名错误");
        }finally {
            scanner.close();
        }
    }
}

*/






/*
public class Main {
    public static void main(String[] args) {
        int[] arr = new int[5];
        for(int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }
        try{
            for(int i = 0; i < 3; i++) {
                System.out.println(arr[i]);
            }
        }catch(ArrayIndexOutOfBoundsException e){
            System.out.println("数组越界了");
        }finally {
            System.out.println("test");
        }
    }
}*/
